<!DOCTYPE html>
<html lang="zh">
<head>
    <title>商户中心</title>
    <{include file="merchant/public/header"}>
    <{include file="merchant/public/data_tables_css"}>

</head>
<body class="hold-transition sidebar-mini layout-fixed">
<!-- Site wrapper -->
<div class="wrapper">
    <!-- Navbar -->
    <{include file="merchant/public/navbar"}>
    <!-- /.navbar -->

    <!-- Main Sidebar Container -->
    <!--左侧菜单-->
    <{include file="merchant/public/sidebar"}>

    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>消息中心</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="<{:url('/plugin/merchant.index/index')}>">首页</a></li>
                            <li class="breadcrumb-item active">消息中心</li>
                        </ol>
                    </div>
                </div>
            </div><!-- /.container-fluid -->
        </section>
        <!-- 内容区-->
        <section class="content">
            <div class="container-fluid">
                <section class="content">
                    <div class="row">

                        <div class="col-md-12">
                            <div class="card card-primary card-outline">

                                <div class="card-header">
                                    <form action="<{:url()}>">
                                        <div class="form-row ">
                                            <div class="col-auto">
                                                <select name="is_read" class="form-control" >
                                                    <option value="">阅读状态</option>
                                                    <option <{if null !== $Request.param.is_read &&$Request.param.is_read=='1'}>selected<{/if}>  value="1">已读</option>
                                                    <option <{if null !== $Request.param.is_read &&$Request.param.is_read=='-1'}>selected<{/if}>  value="-1">未读</option>

                                                </select>
                                            </div>

                                            <div class="col-auto">

                                                <input name="keyword" type="text" class="form-control " placeholder="关键词搜索" value="">
                                            </div>

                                            <div class="col-auto">
                                                <button  type="submit" class="btn btn-primary mb-2 "><i class="fas fa-search"></i></button>


                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <div class="card-body p-0">
                                    <div class="mailbox-controls">
                                        <!-- Check all button -->
                                        <button type="button" class="btn btn-default btn-sm checkbox-toggle"><i class="far fa-square"></i>
                                        </button>
                                        <div class="btn-group">
                                            <button onclick="action('del_all')" type="button" class="btn btn-default btn-sm">
                                                <i class="far fa-trash-alt"></i>
                                            </button>

                                        </div>
                                        <button type="button" title="设为已读"   onclick="action('read_all')"  class="btn btn-default btn-sm">
                                            <i class="fa fa-eye bs-green"></i>
                                        </button>
                                        <!-- /.btn-group -->
                                        <button type="button" onclick="location.reload()" class="btn btn-default btn-sm">
                                            <i class="fas fa-sync-alt"></i>
                                        </button>

                                    </div>
                                    <div class="table-responsive mailbox-messages">
                                        <table class="table table-hover table-striped ">
                                            <tbody>

                                            <{if !empty($data)}>
                                            <{foreach $data as $item}>
                                            <tr>
                                                <td>
                                                    <div class="icheck-primary">
                                                        <input name="ids" type="checkbox" value="<{$item.id}>" id="check<{$item.id}>">
                                                        <label for="check<{$item.id}>"></label>
                                                    </div>
                                                </td>

                                                <td class="mailbox-name"><a href="javascript:void (0)" onclick="detail(this)" class="bs-blue" data-id="<{$item.id}>"><{$item.title}></a></td>
                                                <td class="mailbox-subject"><b><{$item.msg_type_desc}></b> - <{$item.content}>
                                                </td>
                                                <td class="mailbox-read"  data-id="<{$item.id}>">
                                                    <{if $item.read_time}>
                                                    <i class="fa fa-eye bs-green"></i>
                                                    <{else}>
                                                    <i class="fa fa-eye-slash bs-red"></i>
                                                    <{/if}>

                                                </td>
                                                <td class="mailbox-date"><{$item.add_time}></td>
                                            </tr>
                                            <{/foreach}>
                                            <{/if}>



                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="card-footer">
                                    <{$page?$page->render():''}>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </section>

    </div>


</div>
<!-- ./wrapper -->

<{include file="merchant/public/footer"}>
<!-- DataTables  & Plugins -->
<{include file="merchant/public/data_tables"}>
<script>

    function detail(obj){
        var id = $(obj).data('id')
        sendData("<{:url('index')}>",{ac:'get',id:id},function (res) {
            if (res.code==0){
                layer.open({
                    title:res.data.title,
                    content:res.data.content
                })
            }
        },true,false)
    }

    function action(type){
        var values = [];
        $("input[name='ids']:checked").each(function () {
            values.push($(this).val());
        });
        if (values.length<1){
            return layer.msg('请选记录');
        }
        if (type=='del_all'){
            layer.confirm('确定要全部删除吗？',{title:'删除确认'},function () {
                sendData("<{:url('msg_action')}>",{ac:'del_all',values:values},function (res) {
                    if (res.code==0){
                        location.reload()
                    }
                },false,false)
            })
        }else if (type=='read_all') {
            layer.confirm('确定要标记为已读吗？',{title:'修改状态'},function () {
                sendData("<{:url('msg_action')}>",{ac:'read_all',values:values},function (res) {
                    if (res.code==0){
                        location.reload()
                    }
                },false,false)
            })
        }
    }
    $(function () {
        //Enable check and uncheck all functionality
        $('.checkbox-toggle').click(function () {
            var clicks = $(this).data('clicks')
            if (clicks) {
                //Uncheck all checkboxes
                $('.mailbox-messages input[type=\'checkbox\']').prop('checked', false)
                $('.checkbox-toggle .far.fa-check-square').removeClass('fa-check-square').addClass('fa-square')
            } else {
                //Check all checkboxes
                $('.mailbox-messages input[type=\'checkbox\']').prop('checked', true)
                $('.checkbox-toggle .far.fa-square').removeClass('fa-square').addClass('fa-check-square')
            }
            $(this).data('clicks', !clicks)
        })

        //Handle starring for font awesome
        $('.mailbox-star').click(function (e) {
            e.preventDefault()
            //detect type
            var $this = $(this).find('span > i');
            var id = $(this).data('id');
            var cclass    = $this.hasClass('text-warning')

            if (cclass) {
                $this.addClass('text-gray')
                $this.removeClass('text-warning')
            }else {
                $this.removeClass('text-gray')
                $this.addClass('text-warning')
            }
            sendData("msg_action",{ac:'favorite',id:id},function () {

            },true,true)
        });
        $('.mailbox-read').click(function (e) {
            e.preventDefault()
            //detect type
            var $this = $(this).find('i');
            var id = $(this).data('id');
            var cclass    = $this.hasClass('bs-red')

            if (cclass) {
                $this.removeClass('fa-eye-slash bs-red').addClass('fa-eye bs-green')
            }else {
                $this.removeClass('fa-eye bs-green').addClass('fa-eye-slash bs-red')
            }
            sendData("<{:url('msg_action')}>",{ac:'readstate',id:id},function () {

            },true,true)
        })
    })
</script>
<script>
    $(function () {
        $("#my_table").DataTable({
            "ordering": false,//禁用排序
            "responsive": true,
            "lengthChange": false,
            "autoWidth": false,
            //"buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
            // "pageLength": 10,         //初始化显示几条数据
            //serverSide: true, // use local process instead of server
              bFilter: false, // show top right search input box.
            bPaginate: false,//是否开启分页
            iDisplayLength: 10, //默认显示的记录数
            bInfo: false,//是否显示页脚信息，DataTables插件左下角显示记录数
        }).buttons().container().appendTo('#my_table_wrapper .col-md-6:eq(0)');

    });


</script>
<script>

</script>
</body>
</html>
